Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ESIOS API Token support #47

Merged
merged 26 commits into from
Jan 9, 2023
Merged

Implement ESIOS API Token support #47

merged 26 commits into from
Jan 9, 2023

Conversation

azogue
Copy link
Owner

@azogue azogue commented Jan 6, 2023

  • ✨ Implement support to access the extended ESIOS API with a personal token
    (you must request yours by mailing to [email protected]), with initial support for the existent PVPC price sensor (ESIOS indicator code: 1001), and 3 new ones 🤩:

    • Inyection price sensor (ESIOS indicator code: 1739), name: "Precio de la energía excedentaria del autoconsumo para el mecanismo de compensación simplificada"
    • MAG price sensor (ESIOS indicator code: 1900), name: "Desglose peaje por defecto 2.0TD excedente o déficit de la liquidación del mecanismo de ajuste de costes de producción"
    • OMIE price sensor (ESIOS indicator code: 10211), name: "Precio medio horario final suma de componentes"
  • 💥 Remove 'apidatos' support as alternative data-source, leaving only public and private paths for https://api.esios.ree.es

  • ✨ Signal bad auth for esios token calls with a custom exception, to handle 'reauth' flow in Home-Assistant

  • ✨ Add helper methods for HA integration to manage unique ids for each sensor, to update the enabled sensors to download, and to check the API token

  • ♻️ Use dataclasses for EsiosApiData and EsiosResponse data containers, instead of typed dicts

  • ✅ tests: Update fixtures for esios sensors and adapt tests to the new interface and the multiple-sensors behaviour

  • 📦️ Bump mayor version to v4 and lighten dev-env, removing pre-commit related modules and adding python-dotenv

closes #9 #45

* Add optional `esios_api_token` to `PVPCData`, to pair with `data_source="esios"`
* Handle and log error for bad token auth response (401 status) for "esios" source
* Add parsing logic and URL mask for ESIOS indicators data for PVPC (ind=1001)
* Add geozones array to const.py
and instead return an `EsiosApiData` dict when calling `async_update_all`,
as first step to avoid 'state' storage in the API handler, to completely relay
on the DataUpdateCoordinator schema of HA.

Sensor states and attributes are still stored on `.states` and `.sensor_attributes`,
but that should change in the future.

When using the private API with the ESIOS token, both authentication headers are set
(the old with 'Authorization' and the upcoming one with 'x-api-key')

All esios sensors have the same 'price attributes' of the PVPC sensor, excluding
the tariff/period related attrs
to access `ESIOS_TOKEN` env var and make private calls
and lighten dev-env, removing pre-commit related modules and adding python-dotenv
to manage unique ids for each sensor,
and to update the enabled sensors to download
@azogue azogue changed the title Feature/esios token Implement ESIOS API Token support Jan 9, 2023
@azogue azogue merged commit 87e6293 into master Jan 9, 2023
@EddieKnight1
Copy link

Sorry @azogue if I'm posting this in the wrong place.

How do I add this new version to HA? Is it already available as an integration? or should I download it from somewhere else and place it in the custom_components folder?

@azogue
Copy link
Owner Author

azogue commented Jan 10, 2023

Sorry @azogue if I'm posting this in the wrong place.

How do I add this new version to HA? Is it already available as an integration? or should I download it from somewhere else and place it in the custom_components folder?

I have to make a PR in ha-core, and another one in the ha-docs. Then goes the review process, and after the merge, these kind of changes are published in the monthly releases. I'll try to make it for v2023.2.0 🤞, but I'm not sure it will be on time 😰

In the meanwhile, for beta-testing it, you may copy and decompress this pvpc_hourly_pricing.zip into your config/custom_components, to swap the official integration for the new one to come. After release, just remove it 👍

(zip updated at 2023-01-11 09:55h)

@enredador
Copy link

Thank you for the new version @azogue. I have installed it successfully (I will report any other issues). I see that the hourly prizes (current and next day) included in the sensors as attributes are now rendered in €/Mwh whereas the sensor value and some other attributes are in €/Kwh.

@azogue
Copy link
Owner Author

azogue commented Jan 11, 2023

I see that the hourly prizes (current and next day) included in the sensors as attributes are now rendered in €/Mwh whereas the sensor value and some other attributes are in €/Kwh.

Hi @enredador, that was an error 🙈

When developing it, I saw that the new HA frontend renders numeric attributes for entities with 2 decimals max, so for most sensors with values < 100 €/MWh, the price attributes appeared as 0,00 😢

As I was not sure if it was my fault, I changed them to €/MWh, and then I forgot about them 😱

I'll revert it with a new version patch with the fix 🚀

@azogue
Copy link
Owner Author

azogue commented Jan 11, 2023

The zip package is updated to point to "requirements": ["aiopvpc==4.0.1"]
in the manifest.json (it's the only change, if already downloaded, just edit yours) (there are changes in sensor.py too)

@enredador
Copy link

Thank you @azogue. I made the changes and it is running ok now. May be using €-cents/kWh as unit would have been a more readable choice.

@jlopez77
Copy link

This V4.0.1 works fine with the API token. I still can't see surplus (injection) prices, am I doing something wrong?

@azogue
Copy link
Owner Author

azogue commented Apr 2, 2023

This V4.0.1 works fine with the API token. I still can't see surplus (injection) prices, am I doing something wrong?

Hi!

I just published, as a new repository, the 'custom' version of the official component, to replace directly the one included in HA, with the pending changes since January 🐢

It is here: https://github.com/azogue/ha-pvpc-custom

And it is compatible with HACS, adding that link as 'custom repository' with 'category' "Integration" 👍

I recommend everyone to install this new custom component and remove all those components downloaded in some zip (including that 'esios').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Price list for energy injected on the grid when solar installations
4 participants